package com.sfj.system.enums;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author kaka
 * @Date 2025/06/28
 */
//@Deprecated
public enum OrgEnum {

    // 一级组织
    //JIANYU_GUANLIJU(1, "监狱管理局", null),

    // 二级组织
    TILANQIAO(2, "提篮桥监狱", 1),
    XIN_TILANQIAO(3, "新提篮桥", 1),
    WUJIAOCHANG(4, "五角场监狱", 1),
    ZHOUPU(5, "周浦监狱", 1),
    BEIXINJING(6, "北新泾监狱", 1),
    BAIMAOLING(7, "白茅岭", 1),
    JUNTIANHU(8, "军天湖", 1),
    SICHAGE(9, "四岔河", 1),
    WUJIAWA(10, "吴家洼", 1),
    WEICHENGNIAN(11, "未成年犯管教所", 1),
    QINGPU(12, "青浦监狱", 1),
    NVZI(13, "女子监狱", 1),
    XINSHOUFAN(14, "新收犯监狱", 1),
    BAOSHAN(15, "宝山监狱", 1),
    NANHUI(16, "南汇监狱", 1),
    ZONGYIYUAN(17, "监狱总医院", 1),
    SIFAJINGXIAO(18, "司法警校", 1),
    NONGTUIZHAN(19, "农推站", 1),
    XIAYANG(20, "夏阳关押所", 1);

    private final int id;
    private final String name;
    private final Integer parentId;

    OrgEnum(int id, String name, Integer parentId) {
        this.id = id;
        this.name = name;
        this.parentId = parentId;
    }

    public int getId() { return id; }

    public String getName() { return name; }

    public Integer getParentId() { return parentId; }

    public static List<OrgNode> getTree() {
        Map<Integer, OrgNode> map = new LinkedHashMap<>();
        List<OrgNode> tree = new ArrayList<>();

        for (OrgEnum org : OrgEnum.values()) {
            OrgNode node = new OrgNode(org.id, org.name, org.parentId);
            map.put(org.id, node);
        }

        for (OrgNode node : map.values()) {
            if (node.getParentId() == null) {
                tree.add(node);
            } else {
                OrgNode parent = map.get(node.getParentId());
                if (parent != null) {
                    parent.getChildren().add(node);
                }
            }
        }

        return tree;
    }

    public static class OrgNode {
        private int id;
        private String name;
        private Integer parentId;
        private List<OrgNode> children = new ArrayList<>();

        public OrgNode(int id, String name, Integer parentId) {
            this.id = id;
            this.name = name;
            this.parentId = parentId;
        }

        // Getters & Setters
        public int getId() { return id; }
        public String getName() { return name; }
        public Integer getParentId() { return parentId; }
        public List<OrgNode> getChildren() { return children; }
    }
}

